import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;


public class GuitarTest{
	
	public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, InterruptedException
	{
		System.out.println("work");
		
		//Initialization
		GuitarMidi gm = new GuitarMidi();
		GuitarController gc = new GuitarController();
		
		int harm = 0;
		int min = 0;
		int dimSub = 0;
		int trans = 0;
		int whole = 0;
		int octave = 0;
		
		boolean test = true;
		
		//Keeps Program looping
		while(true){
			
			//UpDates Controller Data
			gc.poll();
			
			//Pitch Bend
			if(!gc.back() && !test){
				gm.sendPitchBend(gc.wammyBar());
			}else if(gc.back() && !test){
				gm.sendPitchBend(-gc.wammyBar());
			}
			
			//Mod: Uses "StartPower"
			if(gc.starPower() && !test){
				gm.mod(127);
			}else if(!gc.starPower() && !test){
				gm.mod(0);
			}
			
			//Gets Scale
			if(gc.toggle() == 0){
				min = 0;
				harm = 0;
				dimSub = 0;
				whole = 0;
			}else if(gc.toggle() == 1){
				min = -1;
				harm = 0;
				dimSub = 0;
				whole = 0;
			}else if(gc.toggle() == 2){
				min = -1;
				harm = 1;
				dimSub = 0;
				whole = 0;
			}else if(gc.toggle() == 3){
				min = 0;
				harm = 0;
				dimSub = -1;
				whole = 0;
			}else if(gc.toggle() == 4){
				min = 0;
				harm = 0;
				dimSub = 0;
				whole = 1;
			}
			
			//Octave
			if(gc.blue()){
				octave = 12;
			}else{
				octave = 0;
			}if(gc.orange()){
				octave = -12;
			}
			
			//Transpose Function
			if(gc.keyForward() && trans <= 43){
				trans++;
				Thread.sleep(500);
			}
			if(gc.keyBackward() && trans >= -59){
				trans--;
				Thread.sleep(500);
			}
			
			//Exit
			if(gc.start()){
				System.exit(-1);
			}
			
			//Plays Notes
			if(gc.green() && gc.red() && gc.yellow() && gc.strum()){
				if(test){
					gm.sendNote(72+trans + (2*whole)+octave, 100);
					test = false;
				}
			}else if(gc.red() && gc.yellow() && gc.strum()){
				if(test){
					gm.sendNote(71 + min + trans + harm + dimSub+ whole+octave, 100);
					test = false;
				}
			}else if(gc.green() && gc.yellow() && gc.strum()){
				if(test){
					gm.sendNote(69+min+trans+ whole+octave, 100);
					test = false;
				}
			}else if(gc.green() && gc.red() && gc.strum()){
				if(test){
					gm.sendNote(65+trans+dimSub+whole+octave, 100);
					test = false;
				}
			}else if(gc.yellow() && gc.strum()){
				if(test){
					gm.sendNote(67+trans+dimSub+whole+octave, 100);
					test = false;
				}
			}else if(gc.red() && gc.strum()){
				if(test){
					gm.sendNote(64+min+trans+dimSub+octave, 100);
					test = false;
				}
			}else if(gc.green() && gc.strum()){
				if(test){
					gm.sendNote(62+trans+dimSub+octave, 100);
					test = false;
				}
			}else if(gc.strum()){
				if(test){
					gm.sendNote(60+trans+octave, 100);
					test = false;
				}
			}else if(!test){
				gm.noteOff();
				test = true;
			}
		}
	}
}